const express = require('express');
const handle = require('../router_handle/music_handle');
const app = express.Router();
const multer = require('multer');
const path = require('path');
const storage = multer.diskStorage({
	destination: function (req, file, cb) {
		cb(null, path.join(__dirname, '../uploads/music'));
	},
	filename: function (req, file, cb) {
		cb(null, 'music' + new Date().valueOf() + path.extname(file.originalname));
	}
})
const upload = multer({
	storage
});

// 添加musictype(post)
// /music/addMusicType
// name create_time
app.post('/addMusicType', handle.addMusicType);
// 修改musictype(post)
// /music/editMusicType
// id name(new)
app.post('/editMusicType', handle.editMusicType);
// 删除musictype(get)
// /music/deleteMusicType
// id
app.get('/deleteMusicType', handle.deleteMusicType);
// 查看musictype(get)
// /music/getMusicType
app.get('/getMusicType', handle.getMusicType);
// 通过id获取musictype(get)
// /music/getMusicTypeById
// id
app.get('/getMusicTypeById', handle.getMusicTypeById);

// 添加music(post)
// /music/addMusic
// name musictypeId singerId musicurl musicfile picfile (musicurl musicfile二选一)
app.post('/addMusic', upload.fields([{
	name: 'musicfile'
}, {
	name: 'picfile'
}]), handle.addMusic)
// 删除music(get)
// /music/deleteMusic
// id
app.get('/deleteMusic', handle.deleteMusic);
// 获取music(get)
// /music/getMusic
app.get('/getMusic', handle.getMusic);
// 通过singerid获取music
// /music/getMusicBySingerId
// singerid
app.get('/getMusicBySingerId', handle.getMusicBySingerId)
// 获取music通过musicid
// /music/getMusicById
// id
app.get('/getMusicById', handle.getMusicById);
// 获取music通过musictypeid
// /music/getMusicByMusicTypeId
// musictypeid
app.get('/getMusicByMusicTypeId', handle.getMusicByMusicTypeId)


// 修改music(post)
// /music/editMusic
// id name musictypeId singerId musicurl musicfile picfile (musicurl musicfile二选一)
app.post('/editMusic', upload.fields([{
	name: 'musicfile'
}, {
	name: 'picfile'
}]), handle.editMusic);


module.exports = app